package com.aspira.controller;


import com.aspira.entity.Order;
import com.aspira.entity.OrderItem;
import com.aspira.service.DemoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;


@RestController
@RequestMapping("/api")
public class DemoController {

    @Autowired
    private DemoService service;

    @RequestMapping(value = "/insert", method = RequestMethod.POST)
    public Order insert(RequestOrder requestOrder){
        Order order = new Order();
        order.setUserId(requestOrder.getUserId());
        order.setStatus(requestOrder.getStatus());
        System.out.println("before order: "+ order.getOrderId());

        OrderItem orderItem = new OrderItem();

        orderItem.setUserId(requestOrder.getUserId());
        orderItem.setStatus(requestOrder.getStatus());

        Order order1 = service.insert(order, orderItem);
        return order1;
    }


    @RequestMapping("/all")
    public List<Order> getAllOrder(){
        return service.getAll();
    }

    @RequestMapping("/count")
    public Integer getAllCount(){
        return service.countAll();
    }

    @RequestMapping("/delete")
    public Integer delete(Order order){
        return service.delete(order);
    }


}
